<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./lib/bootstrap3.3.7.css">
    <script src="./lib/moment.2.24.0.js"></script>
    <script src="./lib/vue2.4.4.js"></script>
    <!-- `vue-resource` 依赖于 `vue` -->
    <script src="./lib/vue-resource1.3.4.js"></script>
</head>

<body>
    <div id="app">

        <div class="container">
            <input type="button" value="获取元素" @click="getElement">
            <h3 id="myh3" ref="myh3">{{myh3}}</h3>
            <input type="text" v-model="myh3">
            <hr>
            <login ref="login"></login>
        </div>


    </div>

    <template id="tmpl">
        <h1>登录组件</h1>
    </template>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                myh3: '哈哈哈'
            },
            methods: {
                getElement() {
                    // console.log(document.getElementById('myh3').innerHTML)
                    console.log(this.$refs.myh3.innerText);
                    var mylogin = this.$refs.login;
                    console.log(this.$refs.login);
                    console.log(mylogin.msg);
                    mylogin.show();
                }
            },
            components: {
                login: {
                    template: '#tmpl',
                    data(){
                        return {
                            msg: 'son msg'
                        }
                    },
                    methods: {
                        show() {
                            console.log('调用了子组件的方法');
                        }
                    }
                }
            }
        });
    </script>
</body>

</html>